var  before,after
const onfocusFun = e => {
   e=e || window.event;
  var target=e.target || e.srcElement;
//   console.log(target.getAttribute('states'))
  if(target.getAttribute('states')=='已录取'||target.getAttribute('states')=='已淘汰'){
   // layer.msg("提示：该同学"+target.getAttribute('states')+',可以不用编辑😀')
   layui.use("layer",function(){
      layer.msg("提示：该同学"+target.getAttribute('states')+',可以不用编辑', {
          icon: 6,
          time: 2000
      })
   })
  }
  filtertime_time.style.opacity="0"
   hour_span.style.opacity="0"
   filtertime_minute.style.opacity="0"
   minute_span.style.opacity="0"
  target.style.backgroundColor = "#60B3CA"
  target.style.color = "#fff"
  filtertime_day.innerHTML = '';
  filtertime_day.innerHTML = `
  <option value="-1">？</option>
  <option value="1">1</option>
  <option value="2">2</option>
  <option value="3">3</option>
  <option value="4">4</option>
  <option value="5">5</option>
  <option value="6">6</option>
  <option value="7">7</option>
  <option value="8">8</option>
  <option value="9">9</option>
  <option value="10">10</option>
  <option value="11">11</option>
  <option value="12">12</option>
  <option value="13">13</option>
  <option value="14">14</option>
  <option value="15">15</option>
  <option value="16">16</option>
  <option value="17">17</option>
  <option value="18">18</option>
  <option value="19">19</option>
  <option value="20">20</option>
  <option value="21">21</option>
  <option value="22">22</option>
  <option value="23">23</option>
  <option value="24">24</option>
  <option value="25">25</option>
  <option value="26">26</option>
  <option value="27">27</option>
  <option value="28">28</option>
  <option value="29">29</option>
  <option value="30">30</option>
  <option value="31">31</option>
  `
  filtertime_time.setAttribute('disabled','disabled');
  filtertime_minute.setAttribute('disabled','disabled') 
  
//   console.log(target)
  if (target.innerHTML.trim()=="未设置"||target.innerHTML==null||target.innerHTML.trim()==0) {
     target.innerHTML=""
  }
  before=target.innerHTML;
  if(target.getAttribute("flag")=='1'){
     console.log("---------");
      placeS=target.getAttribute("place");
      filterPlace.style.display="none"
      filterTime.style.display="block"
      submitTimeBtn.style.display="none"
      flagTimeFilter=true
      placeId= target.getAttribute("id")
      indexS= target.getAttribute("name")
      flagDay=false
      flagHour=false
      flagMinute=false
  }else{
     timeS=target.getAttribute("time")
     filterPlace.style.display="block"
     filterTime.style.display="none"
     flagPlaceFilter=true
     placeId= target.getAttribute("id")
     indexS= target.getAttribute("name")
  }
}
const onblurFun = e => {
   e=e || window.event;
  var target=e.target || e.srcElement;
  target.style.backgroundColor = "transparent"
  target.style.color = "#666"
  let time,place;
  if(target.getAttribute("flag")==1){
     time=target.innerHTML
     place=target.getAttribute("place")

  }else{
     place=target.innerHTML
     time=target.getAttribute("time")
   //   filterPlace.style.display="none"
  }
//   console.log(time)
  after=target.innerHTML;
//   console.log(place)
   if(before==after){
      if(before.trim()==0){
         target.innerHTML='未设置'
      }else{
         target.innerHTML=before;
      }
      // console.log(before.trim()==0)
   }else{
      if (target.innerHTML==0||target.innerHTML.trim()=="<br>"||target.innerHTML.trim()=="&nbsp;"||target.innerHTML.trim()=="&nbsp; &nbsp;"||target.innerHTML.trim()=="&nbsp; &nbsp; &nbsp;"||target.innerHTML.trim()=="&nbsp; &nbsp; &nbsp; &nbsp;"||target.innerHTML.trim()=="&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;") {
         target.innerHTML="未设置"
         if(target.getAttribute("flag")==1){
          changeTimePlaceFun(target.getAttribute("id"),"未设置",target.getAttribute("place"))
          document.getElementById("tybody").children[indexS].children[5].setAttribute('time','未设置')
         }else{
          changeTimePlaceFun(target.getAttribute("id"),target.getAttribute("time"),"未设置")
         }
      }else{
       changeTimePlaceFun(target.getAttribute("id"),time,place)
       document.getElementById("tybody").children[indexS].children[5].setAttribute('time',time)
         // success_span.innerHTML = "设置成功"
         // shouSuccessFun()
         // layer.msg('设置成功');
         layui.use("layer",function(){
            layer.msg('设置成功', {
                icon: 1,
                time: 2000
            })
        })
      }
   }
//   console.log(target.innerHTML.trim())
  
}
var filterPlace =qu("#filterPlace");
var filterTime =qu("#timeDiv");
var placeId,placeS,timeS,indexS=0,flagPlaceFilter=false;
var filterDay,filterHour,filterMinute,flagTimeFilter=false;
var flagDay=false,flagHour=false,flagMinute=false
// 选择地点
function filterPlaceFun(){
   if(filterPlace.value!=-1){
      if(flagPlaceFilter==true){
         changeTimePlaceFun(placeId,timeS,filterPlace.value)
         document.getElementById("tybody").children[indexS].children[5].innerHTML=filterPlace.value
         document.getElementById("tybody").children[indexS].children[4].setAttribute("place",filterPlace.value)
         document.getElementById("tybody").children[indexS].children[5].focus()
         flagPlaceFilter=false
      }
      filterPlace.style.display="none"
      // success_span.innerHTML = "设置成功"
      // layer.msg('设置成功');
      layui.use("layer",function(){
         layer.msg('设置成功', {
             icon: 1,
             time: 2000
         })
     })
     filterPlace.innerHTML = `
     <option value="-1">？</option>
      <option value="0#608">0#608</option>
      <option value="0#609">0#609</option>
      <option value="0#611">0#611</option>
      <option value="0#615">0#615</option>
     `
   }
   // shouSuccessFun()
}
// qu("#filtertime_time").style.display="block"
// 选择日期
// console.log(document.querySelector('#filtertime_time'));
function filterDayFun(){
   if(filtertime_day.value!=-1){
      flagDay=true;
      filterDay=filtertime_day.value
      filtertime_time.style.opacity="1"
      hour_span.style.opacity="1"
      if(flagHour!=true){
         filtertime_time.innerHTML = '';
         filtertime_time.innerHTML = `
         <option value="0">？</option>
         <option value="10">10</option>
         <option value="11">11</option>
         <option value="12">12</option>
         <option value="13">13</option>
         <option value="14">14</option>
         <option value="15">15</option>
         <option value="17">17</option>
         <option value="18">18</option>
         <option value="19">19</option>
         <option value="20">20</option>
         <option value="21">21</option>
         <option value="22">22</option>
                           `;
      }
      filtertime_time.removeAttribute('disabled');
   }
}
// 选择小时
function filterHourFun(){
   if(filtertime_time.value!=-1){
      flagHour=true;
      filterHour=filtertime_time.value
      filtertime_minute.style.opacity="1"
      minute_span.style.opacity="1"
      if(flagMinute!=true){
         filtertime_minute.innerHTML = '';
         filtertime_minute.innerHTML = `
         <option value="-1">？</option>
          <option value="00">00</option>
          <option value="05">05</option>
          <option value="10">10</option>
          <option value="15">15</option>
          <option value="20">20</option>
          <option value="25">25</option>
          <option value="30">30</option>
          <option value="35">35</option>
          <option value="40">40</option>
          <option value="45">45</option>
          <option value="50">50</option>
          <option value="55">55</option>`;
      }
   filtertime_minute.removeAttribute('disabled') 
   }
}
// 选择分钟
function filterMinuteFun(){
   if(filtertime_minute.value!=-1){
      flagMinute=true;
      // console.log("小时："+flagHour,"日期："+flagDay,"分："+flagMinute)
      filterMinute=filtertime_minute.value
   }
}
// 确定时间
function filterTimeFun(){
   if(flagTimeFilter==true){
      filterTimeAll=filterDay+"号"+filterHour+":"+filterMinute
      changeTimePlaceFun(placeId,filterTimeAll,placeS)
      document.getElementById("tybody").children[indexS].children[4].innerHTML=filterTimeAll
      document.getElementById("tybody").children[indexS].children[5].setAttribute("place",filterTimeAll)
      document.getElementById("tybody").children[indexS].children[4].focus()
      before=filterTimeAll
      flagTimeFilter=false
   }
   filterTime.style.display="none"
   flagDay=false
   flagHour=false
   flagMinute=false
   // success_span.innerHTML = "设置成功"
   // shouSuccessFun()
   // layer.msg('设置成功');
   layui.use("layer",function(){
      layer.msg('设置成功', {
          icon: 1,
          time: 2000
      })
  })
   filtertime_time.style.opacity="0"
   hour_span.style.opacity="0"
   filtertime_minute.style.opacity="0"
   minute_span.style.opacity="0"
   filtertime_day.innerHTML = '';
   filtertime_time.innerHTML = '';
   filtertime_minute.innerHTML = ''
  
}
// 判断显示提交时间按钮
function judjeTimeFun(){
   if(flagHour==true&&flagMinute==true){
      submitTimeBtn.style.display="block"
   }
   if(flagDay==true&&flagMinute==true){
      submitTimeBtn.style.display="block"
   }
   if(flagDay==true&&filterHour==true){
      submitTimeBtn.style.display="block"
   }
} 
function onFilterPlaceFun(){
   // if(flagPlaceFilter==true){

      // document.getElementById("tybody").children[indexS].children[5].style.backgroundColor = "transparent"

      // document.getElementById("tybody").children[indexS].children[5].style.color = "#fff"

   // }
   
   console.log("---");
}
function changeTimePlaceFun(id,time,place){
   axios({
      url:"/admin/tables/setPlaceAndTime",
      method:"POST",
      params:{
          id:id,
          time:time,
          place:place
          }
      })
      .then(data=>{
         //  console.log(data)
      })
      .catch(err=>{
          console.log(err);
      })
}
// window.onclick = function(e){
//    e=e || window.event;
//    var target=e.target || e.srcElement;
//    if(flagPlaceFilter==true){
//       if(target.getElementById("id")!=""&&target.getAttribute("filterPlace")!="place"){
//          document.getElementById("tybody").children[indexS].children[5].style.backgroundColor = "transparent"
//          document.getElementById("tybody").children[indexS].children[5].style.color = "#666"
//          console.log("+++++++++");
//       }
//    }
  
// }
//  获取后台数据，渲染页面
var tybody = qu("#tybody");
var page=1,
  pageSize=100,
  datas,
  counts=5;
const getDatas=()=>{
  axios({
     url:"/admin/tables/findAllInterviews",
     method:"GET",
     }).then(data=>{
      //   console.log(data)
        datas=data.data.object;
        tybody.innerHTML=''
        let i;
        for(i=0; i<datas.length; i++){
           tybody.innerHTML +=`
           <tr>
              <td>${i+1}</td>
              <td>${datas[i].name}</td>
              <td>${datas[i].classes}</td>
              <td>${datas[i].state}</td>
              <td contentEditable="true" states="${datas[i].state}" flag="1" onfocus="onfocusFun()" onblur="onblurFun()" name="${i}" id="${datas[i].studentId}" place="${datas[i].place}">
              ${datas[i].time==null?"":htmlEscape(datas[i].time)}
              </td>
              <td contentEditable="true" states="${datas[i].state}" class="place" flag="2" onfocus="onfocusFun()" onblur="onblurFun()" name="${i}" id="${datas[i].studentId}"  time="${datas[i].time}">
              ${datas[i].place==null?"":htmlEscape(datas[i].place)}
              </td>
              <td class="interviewers" states="${datas[i].state}" name="${i}" onclick="openAllotWin()" _id="${datas[i].interviewersId}">${datas[i].user==null?'未设置':datas[i].user}</td>
           </tr> 
           `
        }
     }).catch(err=>{
        console.log(err);
     })
}
getDatas();  


// 选择状态
var change_li = cl("change_li");
function chooseStatusFun(e){
  e=e || window.event;
  var target=e.target || e.srcElement;
  for(let key of change_li){
      key.style.backgroundColor="#D8F3EE";
      key.style.color="rgb(115, 111, 111)";
  }
  target.style.backgroundColor = "#2BA5FE"
  target.style.color = "#fff"
}
var filter = qu("#filter");
var trTitle=document.getElementById("trTitle");
var takeMore=document.getElementById("takeMore");
// var tdTime=document.getElementById("tdTime");
// var tdPlace=document.getElementById("tdPlace");
// var tdUser=document.getElementById("tdUser");
var len=7;
function filterFun(){
//   console.log(filter.value)
   filterPlace.style.display="none"
   filterTime.style.display="none"
   filtertime_time.style.opacity="0"
   hour_span.style.opacity="0"
   filtertime_minute.style.opacity="0"
   minute_span.style.opacity="0"
  if(filter.value=="所有人"){
     location.reload();
  }
  axios({
   url:"/admin/tables/findAllInterviews",
   method:"GET",
   }).then(data=>{
    //   console.log(data)
      datas=data.data.object;
      tybody.innerHTML=''
      let i,a=0;
      if(filter.value=='已录取'||filter.value=='已淘汰'){
         trTitle.innerHTML=`
         <td>序号</td>
         <td>姓名</td>
         <td>班级</td>
         <td>内容</td>
      `
      takeMore.style.opacity="0"
         for(i=0; i<datas.length; i++){
            if(datas[i].state==filter.value){
               tybody.innerHTML +=`
               <tr>
                  <td>${a+1}</td>
                  <td>${datas[i].name}</td>
                  <td>${datas[i].classes}</td>
                  <td>${datas[i].state}</td>
               </tr> 
            `
            a++
            }
         }
      } 
      if(filter.value=='待面试'||filter.value=='待一面'||filter.value=='待二面' ||filter.value=='待三面'){
         takeMore.style.opacity="1"
         trTitle.innerHTML=`
         <td>序号</td>
         <td>姓名</td>
         <td>班级</td>
         <td>内容</td>
         <td>时间(可编辑)</td>
         <td>地点(可编辑)</td>
         <td id="tdUser">面试官(可编辑)</td>
      `
         for(i=0; i<datas.length; i++){
            if(datas[i].state==filter.value){
               tybody.innerHTML +=`
               <tr>
                  <td>${a+1}</td>
                  <td>${datas[i].name}</td>
                  <td>${datas[i].classes}</td>
                  <td>${datas[i].state}</td>
                  <td contentEditable="true" states="${datas[i].state}"  flag="1" onfocus="onfocusFun()" onblur="onblurFun()" name="${a}" id="${datas[i].studentId}" place="${datas[i].place}">
                  ${datas[i].time==null?"":htmlEscape(datas[i].time)}
                  </td>
                  <td contentEditable="true" states="${datas[i].state}" class="place" flag="2" onfocus="onfocusFun()" onblur="onblurFun()" name="${a}" id="${datas[i].studentId}"  time="${datas[i].time}">
                  ${datas[i].place==null?"":htmlEscape(datas[i].place)}
                  </td>
                  <td class="interviewers" states="${datas[i].state}" name="${a}" onclick="openAllotWin()" _id="${datas[i].interviewersId}">${datas[i].user==null?'未设置':datas[i].user}</td>
               </tr> 
            `
            a++;
            }
         }
      } 
      if(filter.value=='待笔试'){
         takeMore.style.opacity="1"
         trTitle.innerHTML=`
            <td>序号</td>
            <td>姓名</td>
            <td>班级</td>
            <td>内容</td>
            <td>时间(可编辑)</td>
            <td>地点(可编辑)</td>
         `
         
         for(i=0; i<datas.length; i++){
            if(datas[i].state==filter.value){
               tybody.innerHTML +=`
               <tr>
                  <td>${a+1}</td>
                  <td>${datas[i].name}</td>
                  <td>${datas[i].classes}</td>
                  <td>${datas[i].state}</td>
                  <td contentEditable="true" states="${datas[i].state}"  flag="1" onfocus="onfocusFun()" onblur="onblurFun()" name="${a}" id="${datas[i].studentId}" place="${datas[i].place}">
                  ${datas[i].time==null?"":htmlEscape(datas[i].time)}
                  </td>
                  <td contentEditable="true" states="${datas[i].state}" class="place" flag="2" onfocus="onfocusFun()" onblur="onblurFun()" name="${a}" id="${datas[i].studentId}"  time="${datas[i].time}">
                  ${datas[i].place==null?"":htmlEscape(datas[i].place)}
                  </td>
               </tr> 
            `
            a++
            }
         }
      }
      if(a==0){
         // layer.msg('当前还没有'+filter.value+'的人员');
         layui.use("layer",function(){
            layer.msg('当前还没有'+filter.value+'的人员', {
                icon: 5,
                time: 2000
            })
        })
      }
   }).catch(err=>{
      console.log(err);
   })
 
   //   if(a==0){
   //    success_span.innerHTML = "当前没有"+filter.value+"的同学😉"
   //    shouSuccessFun()
   //   }
}
function exportFun(){
   // console.log(filter.value.trim()=="待面试")
  if(filter.value.trim()=="所有人"){
   //   alert("所有人暂不支持打印")
   layui.use("layer",function(){
      layer.msg('请选择其他状态，‘所有人’状态仅供查看使用', {
          icon: 7,
          time: 2000
      })
  })
   //   success_span.innerHTML = "所有人暂不支持打印"

   //   shouSuccessFun()
  }else{
      if(filter.value.trim()=="已淘汰"||filter.value.trim()=="已录取"){
         realExportFun()
      }else{
         // axios({
         //    url:"/admin/tables/findAllInterviews",
         //    method:"GET",
         //    }).then(data=>{
         //       var flagA=true;
         //       // console.log(data.data.object);
         //       datas=data.data.object;
         //       for(let key of datas){
         //          if(key.state==filter.value){
         //             // console.log(key.time.trim()=="未设置")
         //             if(key.place.trim()=="未设置"||key.time.trim()=="未设置"||key.place.trim()==0||key.time.trim()==0){
         //                // alert("确保时间地点都设置方可下载表格")
         //                layui.use("layer",function(){
         //                   layer.msg('确保时间地点都设置方可下载表格！', {
         //                       icon: 7,
         //                       time: 2000
         //                   })
         //               })
         //                // success_span.innerHTML = "确保时间地点都设置方可下载表格"
         //                // shouSuccessFun();
         //                flagA=false;
         //                return false;
         //              }
         //          }             
         //       }
         //       if(flagA==true){
         //          realExportFun()
         //       }
         //    }).catch(err=>{
         //       alert(err);
         //    })
         realExportFun()
      }
  }
}

function realExportFun(){
   axios({
      url:"/admin/tables/exports", 
      method:"GET",
      params: {
          state:filter.value,
      },
      responseType: 'arraybuffer'
  })
  .then(data=>{
     console.log(data.data);
     if (data.data=="不存在该状态") {
        return alert("不存在该状态,请尝试其他状态")
     }
     let Datas = data.data
     const url = window.URL.createObjectURL(new Blob([Datas], {type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}))
     const link = document.createElement('a')
     link.style.display = 'none'
     link.href = url
     link.setAttribute('download', filter.value+'.xlsx')
     document.body.appendChild(link)
     link.click()
     document.body.removeChild(link)
   })
}
function downLoadXls(data, filename) {
  //var blob = new Blob([data], {type: 'application/vnd.ms-excel'})接收的是blob，若接收的是文件流，需要转化一下
if (typeof window.chrome !== 'undefined') {
  // Chrome version
  var link = document.createElement('a');
  link.href = window.URL.createObjectURL(data);
  link.download = filename;
  link.click();
} else if (typeof window.navigator.msSaveBlob !== 'undefined') {
  // IE version
  var blob = new Blob([data], { type: 'application/force-download' });
  window.navigator.msSaveBlob(blob, filename);
} else {
  // Firefox version
  var file = new File([data], filename, { type: 'application/force-download' });
  window.open(URL.createObjectURL(file));
}
}
function changeAllFun(time,place,state){
   changeWindow.style.display="none"
   cover_div.style.display = 'none'
   axios({
      url:"/admin/tables/changeAll",
      method:"POSt",
      params: {
            place:place,
            state:state,
            time:time
      }
   })
   .then(data=>{
      // alert("修改成功")
      layui.use("layer",function(){
         layer.msg('修改成功！', {
             icon: 1,
             time: 2000
         })
      })
      getDatas()
   })
   .catch(err=>{
     alert(err)
   })
}
// changeBtn.style.display = 'none'
function openChangeAllFun(){
   changeWindow.style.display="block"
   cover_div.style.display = 'block'
}
function closeChangeWindowFun(){
   changeWindow.style.display="none"
   cover_div.style.display = 'none'
}
var times = qu("#times")
var places = qu("#places")
function changeOkFun(){
   if(times.value.trim()==0){
      times.focus()
      // layer.msg('面试时间不能为空')
      layui.use("layer",function(){
         layer.msg('面试时间不能为空', {
             icon: 8,
             time: 2000
         })
      })
   }else if(places.value.trim()==0){
      places.focus();
      // layer.msg('面试地点不能为空');
      layui.use("layer",function(){
         layer.msg('面试地点不能为空', {
             icon: 8,
             time: 2000
         })
      })
   }else{
      changeAllFun(times.value,places.value,filter_then.value)
      
   }
}
// 提示信息
function shouSuccessFun() {
   let i=0;
   successShow.style.display="block"
   let timer=setInterval(function(){
       if(i<1){
           i++
       }else{
           successShow.style.display="none"
           clearInterval(timer);
       }
   },1000)
}
//获取面试官
function getInterviewerFun(){
   axios({  
      url:"/admin/users/findAllUsers",
      method:"GET",
      params: {
          pageNow:1,
          pageSize :500
          }
      })
      .then(function(result){
         // console.log(result.data.user);
         // data_interviews=result.data.user
         for(let i=0;i<result.data.user.list.length;i++){
            data_interviews[i]={
               value:i,
               title:htmlEscape(result.data.user.list[i].name).replace(/[^\u4e00-\u9fa5]/gi, "")
            }
         }
                 
      })
      .catch(err=>{
          console.log(err);
      })
}
var data_interviews = new Array();
getInterviewerFun();
// 穿梭框
function AllotFun(a,b,c){ //a 面试者id b 表格id c面试官
   layui.use(['transfer', 'layer', 'util'], function(){
      // console.log(a);
      // console.log(b);
      // console.log(c.split(' '));
      c=c.split(' ')
      let d = new Array();
      // dels.splice(dels.indexOf(e.target.getAttribute("name"),1))
      if(c!='未设置'){
         let f=0;
         for(let i=0;i<c.length;i++){
            for(let j=0;j<data_interviews.length;j++){
               if(data_interviews[j].title==c[i]){
                  d[f]=data_interviews[j].value;
                  f++
               }
            }
         }
      }
      
      // console.log(d);
      var $ = layui.$
      ,transfer = layui.transfer
      ,layer = layui.layer
      ,util = layui.util;
      
      //模拟数据
      var data1 = [
        {"value": "1", "title": "李白"}
        ,{"value": "2", "title": "杜甫"}
        ,{"value": "3", "title": "苏轼"}
        ,{"value": "4", "title": "李清照"}
        ,{"value": "5", "title": "鲁迅"}
        ,{"value": "6", "title": "巴金"}
        ,{"value": "7", "title": "冰心"}
        ,{"value": "8", "title": "矛盾"}
        ,{"value": "9", "title": "豆腐脑"}
        ,{"value": "16", "title": "驴打滚"}
        ,{"value": "17", "title": "北京烤鸭"}
        ,{"value": "18", "title": "烤冷面"}
        ,{"value": "10", "title": "肉夹馍"}
        ,{"value": "11", "title": "臊子面"}
        ,{"value": "12", "title": "凉皮"}
        ,{"value": "15", "title": "狼牙土豆"}
      ]
      
     
      // console.log(data_interviews)
      
      //实例调用
      
      transfer.render({
        elem: '#test7'
        ,data: data_interviews
        ,id: 'key123' //定义唯一索引
        ,title:['面试官','该同学的面试官']
        ,value:d
        ,showSearch:true
      })
      //批量办法定事件
      util.event('lay-demoTransferActive', {
         getData: function(othis){
          var getData = transfer.getData('key123'); //获取右侧数据
         //  layer.alert(JSON.stringify(getData)); 
          let people ='';
          for(let i=0;i<getData.length;i++){
             people+= getData[i].title
             if(i<getData.length-1){
                people+=' '
             }
          }
          if(people==''){
            document.getElementById("tybody").children[b].children[6].innerHTML="未设置"
          }else{
             document.getElementById("tybody").children[b].children[6].innerHTML=people
          }
         //  console.log(getData);
         closeFun();
         saveInterviews(a,people)
         // layer.msg('设置成功');
        }
        
      });
    });
}
// 保存面试官
function saveInterviews(x,y){
   if(y==''){
      y='未设置'
   }
   axios({
      url:"/admin/tables/changeInterviews",
      method:"POSt",
      params: {
            _id:x,
            interviews:y
      }
   })
   .then(data=>{
      // console.log(x);
      // console.log(y);
      // layer.msg('设置成功');

      layui.use("layer",function(){
         layer.msg('设置成功', {
             icon: 1,
             time: 2000
         })
     })
      
   })
   .catch(err=>{
     alert(err)
   })
}

function openAllotWin(e){
   filtertime_time.style.opacity="0"
   hour_span.style.opacity="0"
   filtertime_minute.style.opacity="0"
   minute_span.style.opacity="0"
   e=e || window.event;
  var target=e.target || e.srcElement;
   // console.log(target.getAttribute('name'));
   // console.log(target.getAttribute('_id'));
   if(window.innerWidth>510){
      if(target.getAttribute('states')=='待面试'||target.getAttribute('states')=='待二面'||target.getAttribute('states')=='待三面'){
         allotWin.style.display = 'block';
         cover_div.style.display = 'block';
         AllotFun(target.getAttribute('_id'),target.getAttribute('name'),target.innerHTML)
      }else{
         // layer.msg(target.getAttribute('states')+"状态无需设置面试官")
         layui.use("layer",function(){
            layer.msg(target.getAttribute('states')+"状态无需设置面试官", {
                icon: 4,
                time: 2000
            })
        })
      }
      
   }else{
      // layer.msg('请使窗口最大化或pc端登录后重试');
      layui.use("layer",function(){
         layer.msg('请使窗口最大化或pc端登录后重试', {
             icon: 4,
             time: 2000
         })
     })
   }
}
var cover_div = document.querySelector("#cover_div");
function closeFun(){
   allotWin.style.display = 'none';
   cover_div.style.display = 'none';
   changeWindow.style.display = 'none';
}
function fliterFlag(){
   console.log(findFlag.value);
   let search_input = document.querySelector('#search_input')
   if(findFlag.value=='0'){
       search_input.setAttribute('placeholder',' 输入姓名')
   }else{
       search_input.setAttribute('placeholder',' 输入班级')
   }
}
//根据姓名查找面试者
function seekUsersFun(e){
   let nav_bottom = qu(".nav_bottom")
   let findP = qu('.findP')
   search_inputText = search_input.value;
   // console.log('123');
   // console.log(typeof search_input.value);//String
   if ( !search_input.value ){
       // alert("请输入您要查找的面试者姓名")
       layui.use("layer",function(){
           layer.msg('请输入您要查找的面试者姓名', {
               icon: 7,
               time: 2000
           })
       })
   } else {
       // console.log('456');
       axios({
           url:"/admin/index/findByNameLike",
           method:"GET",
           params: {
               name:search_input.value,
               choose:findFlag.value 
               }
           })
           .then(data=>{
               // console.log(data.data.data[0]);
               // console.log(data.data.object);
               // console.log(data.data.object.length);
               // console.log(data.data.length);
               // console.log(data.status);
               if(data.status==200){   
                   if(data.data.object==null){
                       // alert('抱歉未找到')
                       layui.use("layer",function(){
                           layer.msg('抱歉未找到', {
                               icon: 7,
                               time: 2000
                           })
                       })
                       
                       // window.location.reload()
                   }else{
                     //   nav_bottom.style.display="none"
                     //   findP.style.display='block'
                     //   findP.innerHTML='为您查找出以下数据:'
                       tybody.innerHTML=''
                       let i,a=0;
                       
                       for(i=0; i<data.data.object.length; i++){
                           tybody.innerHTML +=`
                           <tr>
                           <td>${a+1}</td>
                           <td>${data.data.object[i].name}</td>
                           <td>${data.data.object[i].classes}</td>
                           <td>${data.data.object[i].state}</td>
                           <td contentEditable="true" states="${data.data.object[i].state}"  flag="1" onfocus="onfocusFun()" onblur="onblurFun()" name="${a}" id="${data.data.object[i].studentId}" place="${data.data.object[i].place}">
                           ${data.data.object[i].time==null?"":htmlEscape(data.data.object[i].time)}
                           </td>
                           <td contentEditable="true" states="${data.data.object[i].state}" class="place" flag="2" onfocus="onfocusFun()" onblur="onblurFun()" name="${a}" id="${data.data.object[i].studentId}"  time="${data.data.object[i].time}">
                           ${data.data.object[i].place==null?"":htmlEscape(data.data.object[i].place)}
                           </td>
                           <td class="interviewers" states="${data.data.object[i].state}" name="${a}" onclick="openAllotWin()" _id="${data.data.object[i].interviewersId}">${data.data.object[i].user==null?'未设置':data.data.object[i].user}</td>
                        </tr> 
                          
                           `
                           a++;
                       }
                   }
                   
               }else{
                   // alert("抱歉未找到")
                   layui.use("layer",function(){
                       layer.msg('抱歉未找到', {
                           icon: 7,
                           time: 2000
                       })
                   })
               }   
               search_input.value = ''  
           })
           .catch(err => {
               console.log(err);
           })
   }
}
//回车事件绑定
$('#search_input').bind('keyup', function(event) {
   if (event.keyCode == "13") {
       //回车执行查询
       $('.btn').click();
   }
});